package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public interface SetmealMapper {
    /**
     * 查询总数通过分类id
     * @param id
     * @return
     */
    @Select("select * from setmeal where category_id = #{id}")
    List<Setmeal> getByCateGory(Long id);

    /**
     * 分页查询
     * @param dto
     * @return
     */
    Page<Setmeal> page(SetmealPageQueryDTO dto);

    /**
     * 新增套餐
     * @param setmeal
     */
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into setmeal value (null,#{categoryId},#{name},#{price}," +
            "#{status},#{description},#{image}," +
            "#{createTime},#{updateTime},#{createUser}" +
            ",#{updateUser})")
    void insert(Setmeal setmeal);

    /**
     * 更新套餐
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal getById(Long id);

    /**
     * 根据id查询套餐
     * @param ids
     * @return
     */
    List<Setmeal> getByIds(List<Long> ids);

    /**
     * 删除套餐
     * @param ids
     */

    void deleteBatch(List<Long> ids);

    /**
     * 查询套餐
     * @param categoryId
     * @return
     */
    @Select("select * from setmeal where category_id = #{categoryId} and status = 1")
    List<Setmeal> getByCateGoryAndStatus(Long categoryId);
}
